package com.totem.product.controller;

import com.totem.base.model.Result;
import com.totem.base.mybatis.controller.BaseController;
import com.totem.product.api.ITFundServiceApi;
import com.totem.product.model.TFunds;
import com.totem.product.service.ITFundService;
import com.totem.product.vo.FundVO;
import com.totem.product.vo.SwitchAutoInvestVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
public class FundController extends BaseController<ITFundService, TFunds> implements ITFundServiceApi {
    public Result<List<FundVO>> list() throws IOException {
        List<TFunds> tFunds = service.list();
        List<FundVO> fundVOList = tFunds.stream().map(fund->{
            FundVO vo = new FundVO();
            BeanUtils.copyProperties(fund, vo);
            return vo;
        }).collect(Collectors.toList());
        return Result.success(fundVOList);
    }

    @Override
    public Result<Boolean> switchAutoInvest(SwitchAutoInvestVO switchAutoInvestVO) throws IOException {
        return Result.success(service.switchAutoInvest(switchAutoInvestVO));
    }
}
